﻿using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Searches;

namespace Tests
{
    [TestClass]
    public class OlimpicTests
    {
        [TestMethod]
         public void Task1Test()
         {
             Console.Out.WriteLine(Olimpic.Task1(100));
         }

        [TestMethod]
        public void Task2Test()
        {
            Console.Out.WriteLine(Olimpic.Task2());
        }

        [TestMethod]
        public void Task3Test()
        {
            int task2 = Olimpic.Task2();
            int task3 = Olimpic.Task3(3);
            Console.Out.WriteLine(task3);

            Assert.AreEqual(task2, task3);
            Console.Out.WriteLine(Olimpic.Task3(2));
        }

        [TestMethod]
        public void Task4Test()
        {
            Console.Out.WriteLine(Olimpic.Task4(4, 2));
        }

        [TestMethod]
        public void Task6Test()
        {
            Assert.AreEqual(16, Olimpic.Task6(1, 2, 3, 4, 5, 45));
        }

        [TestMethod]
        public void Task9Test()
        {
            int[,] array = new [,]
                               {
                                   {1, 2, 3},
                                   {3, 2, 1},
                                   {1, 2, 3}
                               };
            int[,] expected = new[,]
                                  {
                                      {1, 6, 12},
                                      {3, 7, 12},
                                      {1, 6, 12}
                                  };

            int[,] actual = array.Task9();

            Print2DArray(actual);

            CollectionAssert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void FillMatrixRightToDiagonals()
        {
            Print2DArray(Olimpic.FillMatrixRightToDiagonals(10));
            Console.WriteLine();
            Print2DArray(Olimpic.FillMatrixRightToDiagonals(9));
        }

        [TestMethod]
        public void FillMatrixDiagonals()
        {
            Print2DArray(Olimpic.FillMatrixDiagonals(5, 5, 3, 3));
            Console.WriteLine();
            Print2DArray(Olimpic.FillMatrixDiagonals(5, 6, 3, 3));
            Console.WriteLine();
            Print2DArray(Olimpic.FillMatrixDiagonals(6, 5, 3, 3));
        }

        private void Print2DArray<T>(T[,] array)
        {
            for (int i = 0; i < array.GetLength(0); i++)
            {
                for (int j = 0; j < array.GetLength(1); j++)
                {
                    Console.Write(array[i, j]);
                    Console.Write(" ");
                }
                Console.WriteLine();
            }
        }
    }
}